﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ManagementProject
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        #region Button_Click_Event
        private void btnOrders_Click(object sender, EventArgs e)
        {
            ShowOrders();
        }

        private void btmEmp_Click(object sender, EventArgs e)
        {
            ShowEmployees();
        }

        private void btnProduct_Click(object sender, EventArgs e)
        {
            ShowProducts();
        }

        private void btnCategory_Click(object sender, EventArgs e)
        {
            ShowCategories();
        }

        private void btnCustomer_Click(object sender, EventArgs e)
        {
            ShowCustomers();
        }

        private void btnSupplier_Click(object sender, EventArgs e)
        {
            ShowSuppliers();
        }

        private void btnShipper_Click(object sender, EventArgs e)
        {
            ShowShippers();
        }

        #endregion

        #region Call_Form_Method
        private void ShowEmployees()
        {
            frmEmployee newFrmEmployee = new frmEmployee();
            if (!IsFormOpened(newFrmEmployee))
            {
                newFrmEmployee.MdiParent = this;
                newFrmEmployee.Show();
            }
        }

        private void ShowProducts()
        {
            frmProduct newFrmProduct = new frmProduct();
            if (!IsFormOpened(newFrmProduct))
            {
                newFrmProduct.MdiParent = this;
                newFrmProduct.Show();
            }
        }
               
        private void ShowCategories()
        {
            frmCategory newFrmCategory = new frmCategory();
            if (!IsFormOpened(newFrmCategory))
            {
                newFrmCategory.MdiParent = this;
                newFrmCategory.Show();
            }
        }
        
        private void ShowCustomers()
        {
            frmCustomers newFrmCustomers = new frmCustomers();
            if (!IsFormOpened(newFrmCustomers))
            {               
                newFrmCustomers.MdiParent = this;
                newFrmCustomers.Show();
            }
        }

        private void ShowOrders()
        {
            frmOrders newFrmOrder = new frmOrders();
            if (!IsFormOpened(newFrmOrder))
            {
                newFrmOrder.MdiParent = this;
                newFrmOrder.Show();
            }
        }

        private void ShowSuppliers()
        {
            frmSupplier newFrmSupplier = new frmSupplier();
            if (!IsFormOpened(newFrmSupplier))
            {
                newFrmSupplier.MdiParent = this;
                newFrmSupplier.Show();
            }
         
        }

        private void ShowShippers()
        {
            frmShippers newFrmShippers = new frmShippers();
            if (!IsFormOpened(newFrmShippers))
            {
                newFrmShippers.MdiParent = this;
                newFrmShippers.Show();                
            }
        }

        #endregion

        #region ToolStrip_Event
        private void tsmEmployee_Click(object sender, EventArgs e)
        {
            ShowEmployees();
        }       

        private void tsmCategories_Click(object sender, EventArgs e)
        {
            ShowCategories();
        }

        private void tsmProducts_Click(object sender, EventArgs e)
        {
            ShowProducts();
        }

        private void tsmCustomer_Click(object sender, EventArgs e)
        {
            ShowCustomers();
        }

        private void tsmOrders_Click(object sender, EventArgs e)
        {
            ShowOrders();
        }

        private void tsmSuppliers_Click(object sender, EventArgs e)
        {
            ShowSuppliers();
        }

        private void tsmShippers_Click(object sender, EventArgs e)
        {
            ShowShippers();
        }

        #endregion

        private void tsmCloseAll_Click(object sender, EventArgs e)
        {
            foreach (Form cForm in this.MdiChildren)
            {
                cForm.Close();
            }
        }

        private bool IsFormOpened(Form f)
        {
            foreach (Form form in this.MdiChildren)
            {
                if (f.GetType().Name == form.GetType().Name)
                    return true;
            }
            return false;
        }

        private void tsmExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

     }
}
